<!---Not in cfscript because I'm lazy and I copied from my other project--->
<cfcomponent output="false">
    
    <cfscript>
        this.UserName = '';
        this.UserPassword = '';
    </cfscript>
    
    
    <cffunction name="init" access="public" returntype="Authenticate" output="false">
        <cfargument name="UserName" type="string" required="true" />
        <cfargument name="Password" type="string" required="true" />        
        <cfscript>
            this.UserName = arguments.UserName;
            this.UserPassword = arguments.Password;
            setAuthentication();
            return this;             
        </cfscript>
    </cffunction>
    
    <cffunction name="setAuthentication" access="private" output="false" returntype="void">
        <cfscript>
            if( CheckPassword() ){
                lock timeout="30" name="#SESSION.IsPasswordGood#" type="Exclusive"{
                    SESSION.IsPasswordGood = 1;
                    SESSION.Authenticated = 1;
                }
            }else{
                SESSION.IsPasswordGood = 0;
                SESSION.Authenticated = 0;
            }       
        </cfscript>
    </cffunction>

    <cffunction name="CheckPassword" returntype="boolean" output="no" access="private">
        <cfset var FUNC = StructNew() />        
        <cfset FUNC.Domain = Iif(Left(this.UserName, 4) NEQ "ANMC", DE('SCF'), DE('ANMC')) />
        <!--- For ANMC double-dippers, strip out the ANMC prefix from their Rosetta Username. --->
        <cfset FUNC.UserName = Iif(Left(this.UserName, 4) NEQ "ANMC", DE(this.UserName), DE(Mid(this.UserName, 5, 99))) />
        <cfntauthenticate domain="#FUNC.Domain#" username="#FUNC.UserName#" password="#this.UserPassword#" result="FUNC.resultAuthenticate" />        
        <cfset FUNC.retval = FUNC.resultAuthenticate.auth />        
        <cfreturn FUNC.retval />    
    </cffunction>   
    
</cfcomponent>